import sympy as sp

# 定义符号变量
x = sp.Symbol('x')

# 定义复杂函数
f = 3*x**2 + 2*sp.sin(x) - 5*sp.exp(x)

print("验证线性性质：")
print(f"原函数：{f}")

# 方法一：直接积分
direct_integral = sp.integrate(f, x)
print(f"直接积分结果：{direct_integral}")

# 方法二：分别积分再组合
part1 = 3 * sp.integrate(x**2, x)
part2 = 2 * sp.integrate(sp.sin(x), x)
part3 = -5 * sp.integrate(sp.exp(x), x)
combined_integral = part1 + part2 + part3
print(f"分别积分组合结果：{combined_integral}")

# 验证两种方法结果是否相同
print(f"结果相同：{sp.simplify(direct_integral - combined_integral) == 0}")